In [1]:
import seaborn as sns
from scipy import signal
from matplotlib import pyplot as plt
%matplotlib inline

Transfer functions

In automatics control (and engineering in general), a transfer function is the relation between the input and the output of a linear time-invariant system with zero initial conditions: $$G(s) = \frac{Y(s)}{X(s)} = \frac{ \mathcal{L}\left\{y(t)\right\} }{ \mathcal{L}\left\{x(t)\right\} }$$

As presented above, Laplace transform is used to change from the time domain to the s-complex domain.

Linear time-invariant systems

Different linear systems can be represented by their transfer function.

For example, a simple $G(s) = \frac{3}{s+5}$ object can be modelled in Python as follows:


In [9]:
numerator = (3, )
denominator = (1, 5)
system = (numerator, denominator)
system_lti = signal.lti(numerator, denominator)

With the help from scipy.signal it's very easy to present typical properties of LTI systems, like step or impulse response, Bode plot or Nyquist plot.

Step response


In [10]:
plt.plot(*signal.step(system))


Out[10]:
[<matplotlib.lines.Line2D at 0x52ef3d0>]

Impulse response


In [4]:
plt.plot(*signal.impulse(system))


Out[4]:
[<matplotlib.lines.Line2D at 0x4a80090>]

In [5]:
# TODO: doesn't work too well, for now :/
# frequency response (is it Nyquist, though???)
plt.plot(*signal.freqresp(system))


/home/piotr/workspace/scientific_python/local/lib/python2.7/site-packages/numpy/core/numeric.py:460: ComplexWarning: Casting complex values to real discards the imaginary part
  return array(a, dtype, copy=False, order=order)
Out[5]:
[<matplotlib.lines.Line2D at 0x4e2a750>]

In [6]:
# Bode diagram
omega, mag, pha = signal.bode(system)
plt.semilogx(omega, mag)
plt.semilogx(omega, pha)


Out[6]:
[<matplotlib.lines.Line2D at 0x52329d0>]